using System;
using System.Text;
using System.Data;
using System.Collections;
using WP.MF.BusinessRule;
using WP.MF.DataEntity;
using WP.MF.DataAccess;
using WP.Commons;
using WP.DB;

namespace WP.MF.BusinessLogical
{
    public class MSysRemarkBLL : IBusinessLogical
    {
		MSysRemarkDAL mSysRemarkDAL = new MSysRemarkDAL();
		public MSysRemarkBLL()
		{
			//
			// TODO: Add constructor logic here
			//
		}

        #region Select Record by RECID OverLoad +1
        public MSysRemarkDEL SelectDataByRecID(DBAccess dBAccess, string strRecId)
        {
            MSysRemarkDEL mSysRemarkDEL = new MSysRemarkDEL();

            DataFunctions.SelectByRecID(dBAccess, mSysRemarkDEL, mSysRemarkDAL.Fields, strRecId);

            return mSysRemarkDEL;
        }

        public IDataEntity SelectDataByRecID(string strRecId)
        {
            DBAccess dBAccess = new DBAccess(false, false);
            try
            {
                MSysRemarkDEL mSysRemarkDEL = SelectDataByRecID(dBAccess, strRecId);
                return mSysRemarkDEL as IDataEntity;
            }
            catch (Exception e)
            {
                ExceptionManager.ProcessException(e);
                return null;
            }
            finally
            {
                dBAccess.CloseCon();
            }
        }
        #endregion

        #region Insert into MSysRemark
        public bool Insert(IDataEntity iContactDEL)
        {
            MSysRemarkDEL mSysRemarkDEL = iContactDEL as MSysRemarkDEL;
            DBAccess dBAccess = new DBAccess(false, true);
            MSysRemarkBRL mSysRemarkBRL = new MSysRemarkBRL();

            try
            {
                //BaseFunctions.SpecialCharDeal(mSysRemarkDEL);

                if (mSysRemarkBRL.InsertValid(dBAccess, mSysRemarkDEL))
                {
                    //Insert Into MSysRemark
                    DataFunctions.InsertTable(dBAccess, mSysRemarkDAL.Fields, mSysRemarkDEL);
                    dBAccess.CommitTranAndCloseCon();
                    return true;
                }
                else
                {
                    dBAccess.RollbackTranAndClose();
                    if (SysVar.ErrorMessage.Count > 0)
                    {
                        MsgBoxEx.Show(SysVar.ErrorMessage, SysVar.WarnTitle);
                    }
                    return false;
                }
            }
            catch (Exception e)
            {
                dBAccess.RollbackTranAndClose();
                ExceptionManager.ProcessException(e);
                return false;
            }
        }
        #endregion

        #region Update MSysRemark
        public bool Update(IDataEntity iContactDEL)
        {
            MSysRemarkDEL mSysRemarkDEL = iContactDEL as MSysRemarkDEL;

            DBAccess dBAccess = new DBAccess(false, true);
            MSysRemarkBRL mSysRemarkBRL = new MSysRemarkBRL();

            try
            {
                //BaseFunctions.SpecialCharDeal(mSysRemarkDEL);

                if (mSysRemarkBRL.UpdateValid(dBAccess, mSysRemarkDEL))
                {
                    //Update MSysRemark
                    DataFunctions.UpdateTable(dBAccess, mSysRemarkDAL.Fields, MSysRemarkDEL.TABLENAME_MSYSREMARK , mSysRemarkDEL.Tables[0].Rows[0]);
                    dBAccess.CommitTranAndCloseCon();
                    return true;
                }
                else
                {
                    dBAccess.RollbackTranAndClose();
                    if (SysVar.ErrorMessage.Count > 0)
                    {
                        MsgBoxEx.Show(SysVar.ErrorMessage, SysVar.WarnTitle);
                    }
                    return false;
                }
            }
            catch (Exception e)
            {
                dBAccess.RollbackTranAndClose();
                ExceptionManager.ProcessException(e);
                return false;
            }
        }
        #endregion

        #region Delete MSysRemark
        public bool Delete(string strRecId,byte[] btOldRecStamp)
        {
            MSysRemarkBRL mSysRemarkBRL = new MSysRemarkBRL();
            DBAccess dBAccess = new DBAccess(false, true);

            try
            {
                if (mSysRemarkBRL.DeleteValid(dBAccess, strRecId, btOldRecStamp))
                {
                    DataFunctions.DeleteByRecID(dBAccess, "MSysRemark", strRecId);

                    dBAccess.CommitTranAndCloseCon();

                    return true;
                }
                else
                {
                    dBAccess.RollbackTranAndClose();
                    if (SysVar.ErrorMessage.Count > 0)
                    {
                        MsgBoxEx.Show(SysVar.ErrorMessage, SysVar.WarnTitle);
                    }
                    return false;
                }
            }
            catch (Exception e)
            {
                dBAccess.RollbackTranAndClose();
                ExceptionManager.ProcessException(e);
                return false;
            }
        }
        #endregion
    }
}
